package com.rt.easyjava.base.biz1.controller;

import com.rt.easyjava.base.biz1.bean.ImportBizData;
import com.rt.easyjava.base.biz1.service.intf.DataBizService;
import com.rt.easyjava.common.base.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;

@RestController
@RequestMapping("/data/")
@Slf4j
@Api(tags = "基于Excel的数据导入")
public class DataController {

    @Resource
    private DataBizService dataBizService;


    @ApiOperation(value = "数据导入", notes = "数据导入：将上传到服务器的文件解析之后放入数据库。" +
            "文件格式：1行1列：tableName,1行2列：属性起始行，1行3列：属性起始列" +
            "2行1列：忽略行（一般为原是表格的表头）；2行2列：数据起始行")
    @PostMapping(value = "import")
    @ResponseBody
    public Result importDataFromExcel(ImportBizData data, MultipartFile file) {
        log.debug("【数据导入】参数：{}", data);
        return dataBizService.importData(data, file);
    }

}
